Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
The es6-shim package is designed to provide compatibility shims so that legacy JavaScript engines behave as closely as possible to ECMAScript 6 (ES6). It includes shims for new methods and functions introduced in ES6, allowing developers to use these features in environments that do not yet support them natively.
Array.prototype methods
Adds new methods to Array.prototype like find, findIndex, etc., enabling more expressive operations on arrays.
[1, 2, 3].find(x => x == 2)
String.prototype methods
Introduces new String methods such as startsWith, endsWith, and includes for easier string manipulation.
'hello'.startsWith('hell')
Number properties
Provides new static properties and methods on the Number object like isNaN and isFinite for improved number checking.
Number.isNaN(NaN)
Promises
Implements Promises for asynchronous programming, following the ES6 specification.
new Promise(function(resolve, reject) { resolve(42); })
Maps and Sets
Adds support for new collection types such as Map and Set, offering more options for data storage and manipulation.
new Map([[1, 'one'], [2, 'two']])
A modular standard library for JavaScript, including polyfills for ECMAScript up to 2021. Offers broader coverage than es6-shim, including proposals not yet standardized.
Part of Babel, this package includes a custom regenerator runtime and core-js. It's more comprehensive but has been deprecated in favor of directly including core-js and the regenerator-runtime.
Focuses on ensuring ECMAScript 5 compatibility, providing shims for older JavaScript engines. It's more focused on ES5, making it complementary rather than directly comparable to es6-shim.
Provides compatibility shims so that legacy JavaScript engines behave as closely as possible to ECMAScript 6 (Harmony).
If you want to use it in browser:
component install paulmillr/es6-shim
if you’re using component(1).bower install es6-shim
if you’re using Twitter Bower.For node.js:
npm install es6-shim
In both browser and node you may also want to include unorm
; see the
String.prototype.normalize
section for
details.
Map
, Set
(requires ES5)Promise
String
:
fromCodePoint()
(a standalone shim is also available)raw()
String.prototype
:
codePointAt()
(a standalone shim is also available)repeat()
(a standalone shim is also available)startsWith()
(a standalone shim is also available)endsWith()
(a standalone shim is also available)contains()
(a standalone shim is also available)Number
:
MAX_SAFE_INTEGER
MIN_SAFE_INTEGER
EPSILON
parseInt()
parseFloat()
isNaN()
(a standalone shim is also available)isInteger()
isSafeInteger()
isFinite()
Array
:
Array.prototype
:
copyWithin()
fill()
find()
(a standalone shim is also available)findIndex()
(a standalone shim is also available)keys()
(note: keys/values/entries return an ArrayIterator
object)entries()
values()
Object
:
getPropertyDescriptor()
(ES5)getPropertyNames()
(ES5)getPropertyKeys()
(ES5)keys()
(ES5)is()
(a standalone shim is also available)assign()
(a standalone shim is also available)setPrototypeOf()
(IE >= 11)Math
:
acosh()
asinh()
atanh()
cbrt()
clz32()
cosh()
expm1()
hypot()
log2()
log10()
log1p()
sign()
sinh()
tanh()
trunc()
imul()
fround()
Math functions accuracy is 1e-11.
The Map
, Set
, and Promise
implementations are subclassable.
You should use the following pattern to create a subclass in ES5 which
will continue to work in ES6:
function MyPromise(exec) {
Promise.call(this, exec);
// ...
}
Object.setPrototypeOf(MyPromise, Promise);
MyPromise.prototype = Object.create(Promise.prototype, {
constructor: { value: MyPromise }
});
Including a proper shim for String.prototype.normalize
would
increase the size of this library by a factor of more than 4.
So instead we recommend that you install the
unorm
package alongside es6-shim
if you need String.prototype.normalize
.
See https://github.com/paulmillr/es6-shim/issues/134 for more
discussion.
It is not possible to implement WeakMap in pure javascript. The es6-collections implementation doesn't hold values strongly, which is critical for the collection. es6-shim decided to not include an incorrect shim.
WeakMap has a very unusual use-case so you probably won't need it at all
(use simple Map
instead).
'abc'.startsWith('a') // true
'abc'.endsWith('a') // false
'john alice'.contains('john') // true
'123'.repeat(2) // '123123'
Object.is(NaN, NaN) // Fixes ===. 0 isnt -0, NaN is NaN
Object.assign({a: 1}, {b: 2}) // {a: 1, b: 2}
Number.isNaN('123') // false. isNaN('123') will give true.
Number.isFinite('asd') // false. Global isFinite() will give true.
// Tests if value is a number, finite,
// >= -9007199254740992 && <= 9007199254740992 and floor(value) === value
Number.isInteger(2.4) // false.
Math.sign(400) // 1, 0 or -1 depending on sign. In this case 1.
[5, 10, 15, 10].find(function(item) {return item / 2 === 5;}) // 10
[5, 10, 15, 10].findIndex(function(item) {return item / 2 === 5;}) // 1
// Replacement for `{}` key-value storage.
// Keys can be anything.
var map = new Map()
map.set('John', 25)
map.set('Alice', 400)
map.set(['meh'], 555)
map.get(['meh']) // undefined because you need to use exactly the same object.
map.delete('Alice')
map.keys()
map.values()
map.size // 2
// Useful for storing unique items.
var set = new Set()
set.add(1)
set.add(5)
set.has(1)
set.has(4) // => false
set.delete(5)
// Promises, see
// http://www.slideshare.net/domenicdenicola/callbacks-promises-and-coroutines-oh-my-the-evolution-of-asynchronicity-in-javascript
// https://github.com/petkaantonov/bluebird/#what-are-promises-and-why-should-i-use-them
Promise.resolve(5).then(function(value) {
if ( ... ) throw new Error("whoops!");
// do some stuff
return anotherPromise();
}).catch(function(e) {
// any errors thrown asynchronously end up here
});
Note that the ES6 Promise
specification includes very few methods.
For a more useful set of utility methods
(map
/reduce
/bind
/guard
/etc), you might want to look into the
prfun
package.
Other stuff:
The project was initially based on es6-shim by Axel Rauschmayer.
Current maintainers are: Paul Miller, Jordan Harband and C. Scott Ananian.
The MIT License (MIT)
Copyright (c) 2013-2014 Paul Miller (http://paulmillr.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
es6-shim 0.11.1 (2 Jun 2014)
FAQs
ECMAScript 6 (Harmony) compatibility shims for legacy JavaScript engines
The npm package es6-shim receives a total of 1,421,217 weekly downloads. As such, es6-shim popularity was classified as popular.
We found that es6-shim demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.